<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>
<script type="text/javascript" src="http://qzonestyle.gtimg.cn/qzone/openapi/qc_loader.js" data-appid="<%=com.oyjd.ybx.fw.util.CodeUtil.qqAppId %>" data-redirecturi="<%=com.oyjd.ybx.fw.util.CodeUtil.webNetName%>/frontSys!qqLoginCallBack.action" charset="utf-8"></script>
<script type="text/javascript" src="http://openapi.baidu.com/connect/js/v2.0/featureloader"></script>
    	<div class="center_hd clearfix" id="loginArea" style="display:none;">
        	<h1>可信赖的婴幼用品导购咨询平台</h1>			
            <ul class="ct_login">
                <li id="li_login"><a href="javascript:viewLogin();" title="登录">登录</a></li>
                <li id="li_regist"><a href="javascript:viewRegist();" title="注册">注册</a></li>
                <li id="li_name" style="display: none;"></li>
                <li id="li_loginout" style="display: none;"><a href="javascript:loginOut();" title="登出">登出</a></li>
            </ul>
            <span style="float:right;margin-right:10px;" id="baidu_bt"><a href="javascript:baiduLogin();">百度登录</a></span>
			<span style="float:right;margin-right:10px;" id="qq_bt"></span>			
        </div>

<script type="text/javascript">

//登入百度
var baiduConnect;
baidu.require('connect', function(connect){
    connect.init('X5AASplHrCfB7jtLeG7aYWKT');
    baiduConnect=connect;
});
function baiduLogin(){
	baiduConnect.login(function(info){
		var bdUrl="<%=com.oyjd.ybx.fw.util.CodeUtil.webNetName%>/frontSys!baiduLoginCallBack.action";
		$.post(bdUrl, "access_token="+info.session.access_token ,function callback(txt){   
			var json = $.parseJSON(txt);
			if (json.code==0) {	
				checkToken();	
			}					
		});
	});		 
}

//登录QQ
QC.Login({
   	size: "B_M",
    btnId:"qq_bt"
});

//设置登录板块可见
function setLoginView(flag){
	document.getElementById('loginArea').style.display=flag?'':'none';
}
//进入登录页面
function viewLogin(){
	location.href="${ctx}/frontSys!viewLogin.action";
}
//进入注册页面
function viewRegist(){
	location.href="${ctx}/frontSys!viewRegist.action";
}
//验证token
function checkToken(){
	var url="${ctx}/frontSys!checkToken.action";
	$.post(url, null ,function callback(txt){ 
		var json = $.parseJSON(txt);				
		if (json.code==0) {	
			$("#li_name").html("欢迎："+json.info.name);
			$("#baidu_bt").hide();
			$("#qq_bt").hide();
			$("#li_login").hide();
			$("#li_regist").hide();			
			$("#li_name").show();
			$("#li_loginout").show();				
		}else{
			$("#baidu_bt").show();
			$("#qq_bt").show();
			$("#li_login").show();
			$("#li_regist").show();
			$("#li_name").hide();
			$("#li_loginout").hide();
		}
		
		//获取收藏
		if(typeof doQueryFavorite == "function"){
			doQueryFavorite();	
		}
		
		//中间栏位
		if(typeof lanShow == "function"){
			lanShow();
		}
		
		//改变点击右边bar填写宝宝资料的响应
		if(typeof clickWriteBabyInfo == "function"){
			clickWriteBabyInfo(json.code==0);
		}
		
		//对话栏右边宝宝信息
		if(typeof talkBabyInfo == "function"){
			talkBabyInfo();
		}
		
	}); 
}
//登出
function loginOut(){
	var url="${ctx}/frontSys!loginOut.action";
	$.post(url, null ,function callback(txt){  
		var json = $.parseJSON(txt);				
		if (json.code==0) {	
			checkToken();					
		}else{
			alert('登出失败');
		}
	}); 
}
</script>